package com.xuyu.nacos.callback.listener.analysekey.onkey;


import com.xuyu.nacos.callback.listener.analysekey.AbstractGetKey;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

/**
 * @author xuyu
 * 处理字段上带了@value的
 */
@Component
public class WithValueAnnotation extends AbstractGetKey<Field> {

    @Override
    public String getKey(Field field) {
        Value value = field.getAnnotation(Value.class);
        return value.value().replace("${", "").replace("}", "");
    }

    @Override
    public boolean choose(Field field) {
        return field.isAnnotationPresent(Value.class);
    }

}
